home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
ddj9304.zip
/
OS2WPS.ZIP
/
WPSPREAD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-18
|
6KB
|
144 lines
[LISTING FOUR]
/* This file was generated by the SOM Compiler. FileName: wpspread.c.
* Generated using: SOM Precompiler spc: 1.22 SOM Emitter emitc: 1.24 */
#define WPSpread_Class_Source
#include "wpspread.ih"
BOOL openfile ( PSZ szFname, LONG alValues[] );
BOOL printspread ( WPSpread *somSelf, PPRINTDEST pPrintDest );;
#undef SOM_CurrentClass
#define SOM_CurrentClass SOMMeta
SOM_Scope PSZ SOMLINK wpspreadM_wpclsQueryTitle(M_WPSpread *somSelf)
{
M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryTitle");
return _wpclsQueryInstanceType( somSelf );
}
SOM_Scope void SOMLINK wpspreadM_wpclsInitData(M_WPSpread *somSelf)
{
HMODULE hmod; // module handle
PSZ psz; // module file name
APIRET rc; // return from API
M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsInitData");
// initialize the parent classes first
parent_wpclsInitData ( somSelf );
// query our module name
psz = _somLocateClassFile( SOMClassMgrObject, SOM_IdFromString( "WPChart" )
, WPSpread_MajorVersion , WPSpread_MinorVersion );
// query our module handle
if ( psz != NULL )
rc = DosQueryModuleHandle ( psz, &hmod );
// load the icon (same as pointer) and store in class data
_hicon = WinLoadPointer ( HWND_DESKTOP, hmod, 1 );
}
SOM_Scope HPOINTER SOMLINK wpspreadM_wpclsQueryIcon(M_WPSpread *somSelf)
{
M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryIcon");
return _hicon;
}
SOM_Scope PSZ SOMLINK wpspreadM_wpclsQueryInstanceFilter(M_WPSpread *somSelf)
{
M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryInstanceFilter");
return ".SPR";
}
SOM_Scope PSZ SOMLINK wpspreadM_wpclsQueryInstanceType(M_WPSpread *somSelf)
{
M_WPSpreadData *somThis = M_WPSpreadGetData(somSelf);
M_WPSpreadMethodDebug("M_WPSpread","wpspreadM_wpclsQueryInstanceType");
return "XX Company Spreadsheet";
}
#undef SOM_CurrentClass
#define SOM_CurrentClass SOMInstance
SOM_Scope BOOL SOMLINK wpspread_wpPrintObject(WPSpread *somSelf,
PPRINTDEST pPrintDest,
ULONG ulReserved)
{
/* WPSpreadData *somThis = WPSpreadGetData(somSelf); */
WPSpreadMethodDebug("WPSpread","wpspread_wpPrintObject");
return printspread ( somSelf, pPrintDest );
}
//************* Following code NOT generated by SOM compiler
// printspread: prints the file this object represents
// RETURNS: TRUE if successful, FALSE if not
BOOL printspread ( WPSpread *somSelf, PPRINTDEST pPrintDest )
{
HDC hdcPrinter; // printer DC
HAB hab; // anchor block handle
HPS hps; // micro PS
SIZEL sizel; // presentation page size
LONG alValues[2]; // spreadsheet values
BOOL fSuccess; // return from API
BOOL lSuccess; // return from API
CHAR szFname[255]; // file name
ULONG cb; // filename length
POINTL ptl; // drawing coordinates
CHAR sz[50]; // temporary string
// create a printer device context
hab = WinQueryAnchorBlock ( HWND_DESKTOP );
hdcPrinter = DevOpenDC ( hab , pPrintDest->lType
, pPrintDest->pszToken , pPrintDest->lCount
, pPrintDest->pdopData , NULLHANDLE );
// create a micro PS associated with the printer DC
sizel.cx = sizel.cy = 0;
hps = GpiCreatePS ( hab, hdcPrinter, &sizel
, GPIT_MICRO | PU_LOENGLISH | GPIA_ASSOC );
// open the file associated with this object
cb = 255;
_wpQueryRealName ( somSelf, szFname, &cb, TRUE );
fSuccess = openfile ( szFname , alValues );
// start a printer job
lSuccess = DevEscape ( hdcPrinter, DEVESC_STARTDOC
, strlen ( _wpQueryTitle ( somSelf ) )
, _wpQueryTitle ( somSelf ) , NULL, NULL );
// print the values
ptl.x = 100; ptl.y = 125;
_itoa ( alValues[0], sz, 10 );
lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
ptl.y = 100;
_itoa ( alValues[1], sz, 10 );
lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
ptl.y = 75;
lSuccess = GpiMove ( hps, &ptl );
ptl.x = 200;
lSuccess = GpiLine ( hps, &ptl );
ptl.x = 100; ptl.y = 50;
_itoa ( alValues[0] + alValues[1], sz, 10 );
lSuccess = GpiCharStringAt ( hps, &ptl, strlen ( sz ) , sz );
// end a printer job
lSuccess = DevEscape ( hdcPrinter, DEVESC_ENDDOC , 0 , NULL, NULL, NULL );
// clean up
DevCloseDC ( hdcPrinter );
GpiDestroyPS ( hps );
return TRUE;
}
// openfile: reads spreadsheet values from the specified file
// RETURNS: TRUE if successful, FALSE if not
BOOL openfile ( PSZ szFname, LONG alValues[] )
{
HFILE h; // file handle
ULONG ulAction; // action taken by OPEN
ULONG ulActualRead; // count read from file
APIRET rc; // return code
// open the file
rc = DosOpen ( szFname, &h, &ulAction, 0L
, 0, OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW
, OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, NULL );
if ( rc != 0 )
return FALSE;
// read the values
rc = DosRead ( h, alValues, 8, &ulActualRead );
if ( ( rc != 0 ) || ( ulActualRead != 8 ) )
{
DosClose ( h );
return FALSE;
}
// close the file
DosClose ( h );
return TRUE;
}